package com.ohuang.demo

import com.google.gson.Gson
import com.ohuang.kthttp.HttpClient
import com.ohuang.kthttp.call.HttpCall
import com.ohuang.kthttp.call.getResult
import com.ohuang.kthttp.urlParams
import kotlinx.coroutines.runBlocking
import org.junit.Test
import java.io.UnsupportedEncodingException
import java.net.URLEncoder

class XiaoHeiApiTest {

    var mHttpClient = HttpClient()
    var gson = Gson()

    @Test
    fun test() {
        runBlocking {
            val string = getGameInfo().getResult()
            println(string)
        }
    }

    /**
     * 编码
     * urlEncode
     */
    private fun String.urlEncode(): String {
        try {
            return URLEncoder.encode(this, "utf-8")
        } catch (e: UnsupportedEncodingException) {
        }
        return this
    }

    /**
     * 解码
     * urlDecode
     */
    private fun String.urlDecode(): String {
        try {
            return java.net.URLDecoder.decode(this, "utf-8")
        } catch (e: UnsupportedEncodingException) {
        }
        return this
    }


    fun getGameInfo(): HttpCall<String> {
        return mHttpClient.stringCall {
            urlParams(
                "http://api.maxjia.com/game/get_game_detail/"
            ) {
                addParam("appid","2933080")
            }
            addHeader("Referer", "http://api.maxjia.com/")
            addHeader(
                "User-Agent",
                "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36 ApiMaxJia/1.0"
            )
//            addHeader(
//                "Cookie",
//                "pkey=MTczOTMyMTg2NS4xOV83NTk1ODkzMnpjZHB2bGR2eWh3Z29rYXU__;x_xhh_tokenid=BFfhcn5uBSnzCBak6DZmcLKsub/yLUqpEKuDXwgr7tSptIMtIC/LYd6SeVJHp8LJCD7b/z1kZg4dOHKWjf14prw=="
//            )
            addHeader("Host", "api.xiaoheihe.cn")
            addHeader("Connection", "Keep-Alive")
            addHeader("Accept-Encoding", "gzip")
        }
    }




}